//
//  SubmitCompanyAuthInfoViewController.m
//  HAODE
//
//  Created by panquanReabam.com on 15/9/15.
//  Copyright (c) 2015年 reabam.com. All rights reserved.
//

#import "SubmitCompanyAuthInfoViewController.h"
#import "VPImageCropperViewController.h"
#import "UpYun.h"
#import "RDVTabBarController.h"
#import "HZAreaPickerView.h"
#import "HAODEsingleton.h"
#import "DailyTableViewCell.h"
#import "TheLoginViewController.h"
#import "HttpRequest.h"
#import "UIButton+WebCache.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import "PECropViewController.h"
#import "renzhengleibieViewController.h"
@interface SubmitCompanyAuthInfoViewController ()<UIScrollViewDelegate, UITextViewDelegate,UIImagePickerControllerDelegate,UIAlertViewDelegate,UIGestureRecognizerDelegate,UITextFieldDelegate,UINavigationControllerDelegate,UIActionSheetDelegate,HZAreaPickerDelegate,VPImageCropperDelegate>
@property (strong, nonatomic) NSString *areaValue;
@property (strong, nonatomic) NSString*cityValue;
@property (strong, nonatomic) HZAreaPickerView *locatePicker;
@property(nonatomic,retain)UIDatePicker* da;
@property (nonatomic, strong) UIImageView *portraitImageView;
@property (nonatomic,strong) UIImagePickerController *ipc;
@property (strong, nonatomic) UIImage *sendImage;
@property (strong, nonatomic) NSString *sat;
@property (strong, nonatomic) NSString *companyImg;
@property (strong, nonatomic) NSString *companyImgWidth;
@property (strong, nonatomic) NSString *companyImgHeight;
@property (strong, nonatomic) NSString*bossIdCardImg;
@property (strong, nonatomic) NSString *bossIdCardImgWidth;
@property (strong, nonatomic) NSString *bossIdCardImgHeight;
@property (strong, nonatomic) NSString*businessLicenseImg;
@property (strong, nonatomic) NSString *businessLicenseImgWidth;
@property (strong, nonatomic) NSString *businessLicenseImgHeight;
@property (strong, nonatomic) NSString *logoImgWidth;
@property (strong, nonatomic) NSString *logoImgHeight;
@property (strong, nonatomic) NSString*logo;
@property (nonatomic,retain)NSString*jzdprovince;
@property (nonatomic,retain)NSString*jzdcity;
@property (nonatomic,retain)NSString*jzddistrict;
@property (nonatomic) UIPopoverController *popover;
@end

@implementation SubmitCompanyAuthInfoViewController

{
    UITextField*closeTimeTextFied;
    UITextField*openTimeTextFied;
    UITextField*companyNameTextField;
    UIScrollView*mainScroll;
    UITextField*phoneTextFied;
    UITextView*tv;
    UITextField*AddressTextFied;
    UITextField*ProvinceNameTextFied;
    UITextField*ownerCardNoTextFied;
    UITextField*bossIdCardNoTextFied;
    UITextField*bossNameTextField;
    UITextField*ownerNameTextField;
    UITextField*ownerHouseNoTextFied;
    UITextField*bTypeListTextField;
    UIButton*agreementBtn;
    UIButton*renzheng;
    BOOL saveAccount;
    UIImageView*imagess;
    UIButton*mendianimage;
    UIButton*farennimage;
    UIButton*yingyeimage;
    UIImage *image;
    UIButton*imageView;
    HAODEsingleton*commdity;
    NSMutableArray *selectFeatureCodeArray;
    NSMutableArray *selectFeaturenameArray;
    UILabel *label1;
    UILabel *label2;
    UILabel *label3;
    UILabel *label4;
    UIView* view3;
    UIView*view5;
    NSDictionary*dic;
    NSString*str;
    UIImage *image1;
}

@synthesize alt = alt;
@synthesize areaValue=_areaValue, cityValue=_cityValue;
@synthesize locatePicker=_locatePicker;

-(void)setAreaValue:(NSString *)areaValue
{
    if (![_areaValue isEqualToString:areaValue]) {
    
        ProvinceNameTextFied.text = areaValue;
  
    }
}

-(void)setCityValue:(NSString *)cityValue
{
    if (![_cityValue isEqualToString:cityValue]) {
       
        ProvinceNameTextFied.text = cityValue;
    }
}

#pragma mark - HZAreaPicker delegate
-(void)pickerDidChaneStatus:(HZAreaPickerView *)picker
{
    if (picker.pickerStyle == HZAreaPickerWithStateAndCityAndDistrict) {
        self.areaValue = [NSString stringWithFormat:@"%@ %@ %@", picker.locate.state, picker.locate.city, picker.locate.district];
       
        
        self.jzdprovince= picker.locate.state;
        self.jzdcity=picker.locate.city;
        self.jzddistrict=picker.locate.district;
        
        
        
    } else{
        self.cityValue = [NSString stringWithFormat:@"%@ %@", picker.locate.state, picker.locate.city];
        
    }
}
-(void)area:(UIButton*)sender{
    
    
    [closeTimeTextFied resignFirstResponder];
    [openTimeTextFied resignFirstResponder];
    [companyNameTextField resignFirstResponder];
    [ProvinceNameTextFied resignFirstResponder];
    [phoneTextFied resignFirstResponder];
    [AddressTextFied resignFirstResponder];
    
    
    [self cancelLocatePicker];
    self.locatePicker = [[HZAreaPickerView alloc] initWithStyle:HZAreaPickerWithStateAndCityAndDistrict delegate:self] ;
    [self.locatePicker showInView:self.view];
    
    
    
}

-(void)cancelLocatePicker
{
    [self.locatePicker cancelPicker];
    self.locatePicker.delegate = nil;
    self.locatePicker = nil;
}


#pragma mark - TextField delegate

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    [self cancelLocatePicker];
}

- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    
    
    
    self.navigationController.delegate = nil;
    
}
-(void)BackAction:(UIButton *)sender{
    
    
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    self.navigationController.delegate = self;
    
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];
    
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBarHidden = NO;
        self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];
    
    
    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setValue:Token forKey:@"tokenId"];
    [params setValue:@"auth" forKey:@"uploadType"];
    
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    [HttpRequest requestData:@"Common/GetUpyunFormParams" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                
                NSLog(@"%@",severDataDict.dataDict);
                
                NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
                NSString*policy=[severDataDict.dataDict objectForKey:@"policy"];
                NSString*signature=[severDataDict.dataDict objectForKey:@"signature"];
                NSString*action=[severDataDict.dataDict objectForKey:@"action"];
                [user setObject:signature forKey:@"signature"];
                [user setObject:policy forKey:@"policy"];
                [user setObject:action forKey:@"action"];
                [user synchronize];
                
            }else{
    
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    commdity=[HAODEsingleton shared];
   
   
   
    
    
    if (commdity.leibeicode.count>0) {
    selectFeaturenameArray=[[NSMutableArray alloc]init];
    selectFeatureCodeArray=[[NSMutableArray alloc]init];
    selectFeatureCodeArray=commdity.leibeicode;
    selectFeaturenameArray=commdity.leibeicontent;
    

    NSLog(@"----======%@",commdity.leibeicode);
    NSLog(@"---------%@",commdity.leibeicontent);
        
        NSString*  string=[[NSString alloc]init];
        for(int i = 0; i < selectFeaturenameArray.count; i++){
            string = [string stringByAppendingString:[NSString stringWithFormat:@"%@  ",  selectFeaturenameArray[i]]];
            
        }
        NSLog(@"=========%@",string);
        bTypeListTextField.text=string;
    }
    
    
    
    
    
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    selectFeaturenameArray=[[NSMutableArray alloc]init];
    selectFeatureCodeArray=[[NSMutableArray alloc]init];
    mainScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, ScreenWidth, ScreenHeight)];
    
    
    [mainScroll setBackgroundColor:zuiqianhuicolor];
    mainScroll.delegate = self;
    mainScroll.userInteractionEnabled = YES;
    mainScroll.scrollEnabled = YES;
    [self.view addSubview:mainScroll];
   
    self.title = @"新增认证门店";
    
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     backColor,
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    
  
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setValue:Token forKey:@"tokenId"];
    
    
    
    [HttpRequest requestData:@"System/GetCompanyAuthInfo" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                
                NSLog(@"%@",severDataDict.dataDict);
                
          
                dic=[severDataDict.dataDict objectForKey:@"companyAuthInfo"];
                
        
                _da = [[UIDatePicker alloc] init];
                [_da addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];
                _da.datePickerMode = UIDatePickerModeTime;
                _da.backgroundColor=[UIColor whiteColor];
          
             
                // 手势
                UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
                singleFingerOne.numberOfTouchesRequired = 1; //手指数
                singleFingerOne.numberOfTapsRequired = 1; //tap次数
                singleFingerOne.delegate = self;
                [mainScroll addGestureRecognizer:singleFingerOne];
                UIView * view=[[UIView alloc]initWithFrame:CGRectMake(0, 10, ScreenWidth, 120)];
                view.backgroundColor=[UIColor whiteColor];
                [mainScroll addSubview:view];
                
                
                mendianimage=[[UIButton alloc]initWithFrame:CGRectMake(15, 10, ScreenWidth-30, 100)];
                [mendianimage setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"companyImgUrlFull"]] placeholderImage:[UIImage imageNamed:@"shangchaun1"]];
                [view addSubview:mendianimage];
                
                UITapGestureRecognizer *portraitTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(editPortrait)];
                [mendianimage addGestureRecognizer:portraitTap];
                
                
                UIView* myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
                myToolBar.backgroundColor=jianpancolor;
                UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
                [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
                [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
                [myToolBar addSubview:tubtnDone];
                UIButton*btnDone111=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
                [btnDone111 setTitle:@"确定" forState:UIControlStateNormal];
                [btnDone111 setTitleColor:jianpancolor1 forState:UIControlStateNormal];
                btnDone111 .titleLabel .font=[UIFont systemFontOfSize:daxiao];
                [btnDone111 addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
                [myToolBar addSubview:btnDone111];
                myToolBar.alpha=alp;
                UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
                [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
                [myToolBar addSubview:dabtn];
                
                
                
                
                UIView * logoview1=[[UIView alloc]initWithFrame:CGRectMake(0, view.bottom+10, ScreenWidth, 80)];
                logoview1.backgroundColor=[UIColor whiteColor];
                [mainScroll addSubview:logoview1];
                UILabel *line161 = [[UILabel alloc]initWithFrame:CGRectMake(15,80-0.35, ScreenWidth-30, 0.35)];
                line161.backgroundColor = labelColor;
                [logoview1 addSubview:line161];
                UILabel* pinpai=[[UILabel alloc]initWithFrame:CGRectMake(20, 0, 70,80)];
                pinpai.text=[NSString stringWithFormat:@"%@", @"品牌标志"];
                pinpai.font=[UIFont systemFontOfSize:contenfot];
                pinpai.textColor=[UIColor blackColor];
                [logoview1 addSubview:pinpai];
                
                UITextField*Field=[[UITextField alloc]initWithFrame:CGRectMake(pinpai.right,0, ScreenWidth*500/750,  80)];
                Field.borderStyle = UITextBorderStyleNone;
                Field.font = [UIFont systemFontOfSize: contenfot];
                Field.textColor=[UIColor blackColor];
                Field.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                Field.tag=1;
                Field.placeholder = @"请上传品牌LOGO"; //默认显示的字
                Field.delegate = self;
                [Field setUserInteractionEnabled:NO];
                Field.clearButtonMode = UITextFieldViewModeWhileEditing;
                [logoview1 addSubview:Field];
                
                UITapGestureRecognizer *portraitTaplogo = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(editPortraitlogo)];
                
                imageView = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-110, 10, 120/2, 120/2)];
                imageView.layer.masksToBounds = YES;
//                [imageView setBackgroundImage:[UIImage imageNamed:@"logorenzheng"] forState:UIControlStateNormal];
                [imageView setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"logoImgUrlFull"]] placeholderImage:[UIImage imageNamed:@"logorenzheng"]];
                imageView.layer.cornerRadius = 120/2/2;
            
                [imageView addGestureRecognizer:portraitTaplogo];
                [logoview1 addSubview:imageView];
                UIButton*jiantouBtn34 = [[UIButton alloc]init];
                jiantouBtn34.frame = CGRectMake(ScreenWidth-30,35,8, 13);
                [jiantouBtn34 setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
                [logoview1 addSubview:jiantouBtn34];
                
                
                UIView * view1=[[UIView alloc]initWithFrame:CGRectMake(0, logoview1.bottom, ScreenWidth, 350)];
                view1.backgroundColor=[UIColor whiteColor];
                [mainScroll addSubview:view1];
                
                UILabel* companyName=[[UILabel alloc]initWithFrame:CGRectMake(20, 0, 70,45)];
                companyName.text=[NSString stringWithFormat:@"%@", @"门店名称"];
                companyName.font=[UIFont systemFontOfSize:contenfot];
                companyName.textColor=[UIColor blackColor];
                [view1 addSubview:companyName];
                
                companyNameTextField=[[UITextField alloc]initWithFrame:CGRectMake(companyName.right,0, ScreenWidth*500/750,  45)];
                companyNameTextField.borderStyle = UITextBorderStyleNone;
                companyNameTextField.font = [UIFont systemFontOfSize: contenfot];
                companyNameTextField.textColor=[UIColor blackColor];
                companyNameTextField.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                companyNameTextField.tag=1;
                companyNameTextField.placeholder = @"请输入门店名称"; //默认显示的字
                companyNameTextField.delegate = self;
                companyNameTextField.text= [dic objectForKey:@"companyName"];
                [companyNameTextField setUserInteractionEnabled:YES];
                companyNameTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
                [view1 addSubview:companyNameTextField];
                
                
                
                UILabel* openTime=[[UILabel alloc]initWithFrame:CGRectMake(20, 45,70,45)];
                openTime.text=[NSString stringWithFormat:@"%@", @"营业时间"];
                openTime.font=[UIFont systemFontOfSize:contenfot];
                openTime.textColor=[UIColor blackColor];
                [view1 addSubview:openTime];
                
                
                
                openTimeTextFied=[[UITextField alloc]initWithFrame:CGRectMake(openTime.right,  45, 120,  45)];
                openTimeTextFied.borderStyle = UITextBorderStyleNone;
                openTimeTextFied.font = [UIFont systemFontOfSize: contenfot];
                openTimeTextFied.textColor=[UIColor blackColor];
                openTimeTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                openTimeTextFied.tag=2;
                openTimeTextFied.placeholder = @"请输入开始时间"; //默认显示的字
                openTimeTextFied.delegate = self;
                openTimeTextFied.text=[dic objectForKey:@"openTime"];
                openTimeTextFied.textAlignment=NSTextAlignmentCenter;
                [openTimeTextFied setUserInteractionEnabled:YES];
                openTimeTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
                [view1 addSubview:openTimeTextFied];
                
                UILabel* fuhao=[[UILabel alloc]initWithFrame:CGRectMake(openTimeTextFied.right, 45,15,45)];
                fuhao.text=[NSString stringWithFormat:@"%@", @"～～"];
                fuhao.font=[UIFont systemFontOfSize:contenfot];
                fuhao.textColor=[UIColor blackColor];
                [view1 addSubview:fuhao];
                
                closeTimeTextFied=[[UITextField alloc]initWithFrame:CGRectMake(fuhao.right,  45, 120,  45)];
                closeTimeTextFied.borderStyle = UITextBorderStyleNone;
                closeTimeTextFied.font = [UIFont systemFontOfSize: contenfot];
                closeTimeTextFied.textColor=[UIColor blackColor];
                closeTimeTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                closeTimeTextFied.tag=3;
                closeTimeTextFied.placeholder = @"请输入结束时间"; //默认显示的字
                closeTimeTextFied.textAlignment=NSTextAlignmentCenter;
                closeTimeTextFied.text= [dic objectForKey:@"closeTime"];
                closeTimeTextFied.delegate = self;
                [closeTimeTextFied setUserInteractionEnabled:YES];
                closeTimeTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
                [view1 addSubview:closeTimeTextFied];
                [_da setAccessibilityLanguage:@"Chinese"];
                
                openTimeTextFied.inputView = _da;
                closeTimeTextFied.inputView = _da;
                UILabel*  phone=[[UILabel alloc]initWithFrame:CGRectMake(20, 90, 70,45)];
                phone.text=[NSString stringWithFormat:@"%@", @"联系电话"];
                phone.font=[UIFont systemFontOfSize:contenfot];
                phone.textColor=[UIColor blackColor];
                [view1 addSubview: phone];
                phoneTextFied=[[UITextField alloc]initWithFrame:CGRectMake( phone.right,  90, ScreenWidth*500/750,  45)];
                phoneTextFied.borderStyle = UITextBorderStyleNone;
                phoneTextFied.keyboardType = UIKeyboardTypeDecimalPad;
                phoneTextFied.font = [UIFont systemFontOfSize: contenfot];
                phoneTextFied.textColor=[UIColor blackColor];
                phoneTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                phoneTextFied.tag=4;
                 phoneTextFied.text= [dic objectForKey:@"phone"];
                phoneTextFied.placeholder = @"请输入联系电话"; //默认显示的字
                [phoneTextFied setUserInteractionEnabled:YES];
                [phoneTextFied addTarget:self action:@selector(userNumberLimitTextLength:) forControlEvents:UIControlEventEditingChanged];
                
                phoneTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
                [view1 addSubview:phoneTextFied];
                
                
                UILabel* ProvinceName=[[UILabel alloc]initWithFrame:CGRectMake(20, 135, 70,45)];
                ProvinceName.text=[NSString stringWithFormat:@"%@", @"地区"];
                ProvinceName.font=[UIFont systemFontOfSize:contenfot];
                ProvinceName.textColor=[UIColor blackColor];
                [view1 addSubview:ProvinceName];
                UIButton*area=[[UIButton alloc]initWithFrame:CGRectMake(ProvinceName.right, 135, ScreenWidth, 30)];
                [area addTarget:self action:@selector(area:) forControlEvents:UIControlEventTouchUpInside];
                [view1 addSubview:area];
                UIButton*jiantouBtn3 = [[UIButton alloc]init];
                jiantouBtn3.frame = CGRectMake(ScreenWidth-30,150,8, 13);
                [jiantouBtn3 setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
                [view1 addSubview:jiantouBtn3];
                
                ProvinceNameTextFied=[[UITextField alloc]initWithFrame:CGRectMake(ProvinceName.right,  135, ScreenWidth*500/750,  45)];
                ProvinceNameTextFied.borderStyle = UITextBorderStyleNone;
                ProvinceNameTextFied.font = [UIFont systemFontOfSize: contenfot];
                ProvinceNameTextFied.textColor=[UIColor blackColor];
                ProvinceNameTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                ProvinceNameTextFied.tag=5;
                if ([[dic objectForKey:@"province"]isEqualToString:@""]) {
                    
                }else{
                    if ([dic objectForKey:@"province"]==nil) {
                         [[dic objectForKey:@"province"] isEqual:@""];
                         [[dic objectForKey:@"city"] isEqual:@""];
                    }
                    ProvinceNameTextFied.text= [dic objectForKey:@"province"];
                
                    self.jzdprovince=[dic objectForKey:@"province"];
                    self.jzdcity=[dic objectForKey:@"city"];
                    self.jzddistrict=[dic objectForKey:@"region"];
                }
                ProvinceNameTextFied.placeholder = @"请选择地区"; //默认显示的字
                [ProvinceNameTextFied setUserInteractionEnabled:NO];
                ProvinceNameTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
                [view1 addSubview:ProvinceNameTextFied];
                
                
                
                
                UILabel* Address=[[UILabel alloc]initWithFrame:CGRectMake(20, 180, 70,45)];
                Address.text=[NSString stringWithFormat:@"%@", @"详细地址"];
                Address.font=[UIFont systemFontOfSize:contenfot];
                Address.textColor=[UIColor blackColor];
                [view1 addSubview:Address];
                AddressTextFied=[[UITextField alloc]initWithFrame:CGRectMake(Address.right,  180, ScreenWidth*550/750,  45)];
                AddressTextFied.borderStyle = UITextBorderStyleNone;
                AddressTextFied.font = [UIFont systemFontOfSize: contenfot];
                AddressTextFied.textColor=[UIColor blackColor];
                AddressTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                AddressTextFied.tag=6;
                AddressTextFied.placeholder = @"请输入详细地址"; //默认显示的字
                [AddressTextFied setUserInteractionEnabled:YES];
                AddressTextFied.delegate = self;
                AddressTextFied.text= [dic objectForKey:@"address"];
                AddressTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
                [view1 addSubview:AddressTextFied];
                
                
                
                
                tv=[[UITextView alloc]init];
                tv.frame=CGRectMake(15, AddressTextFied.bottom+20, ScreenWidth-30, 90);
                tv.backgroundColor = [UIColor whiteColor];//设置它的背景颜色/Users/jiezsoft/Desktop/
                tv.scrollEnabled = YES;//是否可以拖动
                tv.delegate=self;
                tv.font = [UIFont fontWithName:@"Arial" size:15.0];//设置字体名字和字体大小
                tv.layer.borderWidth =0.45;
                CGColorSpaceRef registedSpace11 = CGColorSpaceCreateDeviceRGB();
                CGColorRef tureBTncolorref111 = CGColorCreate(registedSpace11,(CGFloat[]){ 0, 0, 0, 0.3 });
                //                tv.keyboardType = UIKeyboardTypePhonePad;
                [tv.layer setBorderColor:tureBTncolorref111];//边框颜色
                tv.layer.cornerRadius =0;
                [view1 addSubview:tv];
                
                
                if ([[dic objectForKey:@"details"]isEqualToString:@""]) {
                    imagess=[[UIImageView alloc]initWithFrame:CGRectMake(15, 10, 51/3, 43/3)];
                    imagess.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
                    [tv addSubview:imagess];
                }else{
                
                    tv.text=[dic objectForKey:@"details"];
                }
               
                
                UILabel *line1 = [[UILabel alloc]initWithFrame:CGRectMake(15,0, ScreenWidth-30, 0.35)];
                line1.backgroundColor = labelColor;
                //  [view1 addSubview:line1];
                UILabel *line11 = [[UILabel alloc]initWithFrame:CGRectMake(15,45, ScreenWidth-30, 0.35)];
                line11.backgroundColor = labelColor;
                [view1 addSubview:line11];
                UILabel *line111 = [[UILabel alloc]initWithFrame:CGRectMake(15,90, ScreenWidth-30, 0.35)];
                line111.backgroundColor = labelColor;
                [view1 addSubview:line111];
                UILabel *line1111 = [[UILabel alloc]initWithFrame:CGRectMake(15,135, ScreenWidth-30, 0.35)];
                line1111.backgroundColor = labelColor;
                [view1 addSubview:line1111];
                UILabel *line12 = [[UILabel alloc]initWithFrame:CGRectMake(15,180, ScreenWidth-30, 0.35)];
                line12.backgroundColor = labelColor;
                [view1 addSubview:line12];
                UILabel *line13 = [[UILabel alloc]initWithFrame:CGRectMake(15,225, ScreenWidth-30, 0.35)];
                line13.backgroundColor = labelColor;
                [view1 addSubview:line13];
                //22222222222
                UIView * view2=[[UIView alloc]initWithFrame:CGRectMake(0, view1.bottom+10,ScreenWidth, 150+45)];
                view2.backgroundColor=[UIColor whiteColor];
                [mainScroll addSubview:view2];
                UILabel*wukuanrenzhen=[[UILabel alloc]initWithFrame:CGRectMake(15, 21, 2, 17)];
                wukuanrenzhen.backgroundColor=luseColor;
                [view2 addSubview:wukuanrenzhen];
                UILabel*wukuanrenzhen1=[[UILabel alloc]initWithFrame:CGRectMake(wukuanrenzhen.right+5, 0, 70, 60)];
                wukuanrenzhen1.text=@"物管认证";
                [view2 addSubview:wukuanrenzhen1];
                UILabel*wukuanrenzhen2=[[UILabel alloc]initWithFrame:CGRectMake(wukuanrenzhen1.right+5, 0, 250, 60)];
                wukuanrenzhen2.text=@"(认证后可以享受物业费线上优惠缴纳)";
                wukuanrenzhen2.textColor=luseColor;
                wukuanrenzhen2.font=[UIFont systemFontOfSize:15];
                [view2 addSubview:wukuanrenzhen2];
                
                
                
                UILabel* ownerName=[[UILabel alloc]initWithFrame:CGRectMake(20, 60, 70,45)];
                ownerName.text=[NSString stringWithFormat:@"%@", @"户主姓名"];
                ownerName.font=[UIFont systemFontOfSize:contenfot];
                ownerName.textColor=[UIColor blackColor];
                [view2 addSubview:ownerName];
                
                ownerNameTextField=[[UITextField alloc]initWithFrame:CGRectMake(companyName.right,60, ScreenWidth*500/750,  45)];
                ownerNameTextField.borderStyle = UITextBorderStyleNone;
                ownerNameTextField.font = [UIFont systemFontOfSize: contenfot];
                ownerNameTextField.textColor=[UIColor blackColor];
                ownerNameTextField.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                ownerNameTextField.tag=7;
                ownerNameTextField.placeholder = @"请输入户主姓名"; //默认显示的字
                ownerNameTextField.delegate = self;
                ownerNameTextField.text=[dic objectForKey:@"ownerName"];
                [ownerNameTextField setUserInteractionEnabled:YES];
                ownerNameTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
                [view2 addSubview:ownerNameTextField];
                
                UILabel* ownerHouseNo=[[UILabel alloc]initWithFrame:CGRectMake(20, 105,70,45)];
                ownerHouseNo.text=[NSString stringWithFormat:@"%@", @"门店编号"];
                ownerHouseNo.font=[UIFont systemFontOfSize:contenfot];
                ownerHouseNo.textColor=[UIColor blackColor];
                [view2 addSubview:ownerHouseNo];
                
                ownerHouseNoTextFied=[[UITextField alloc]initWithFrame:CGRectMake(openTime.right,  105, ScreenWidth*500/750,  45)];
                ownerHouseNoTextFied.borderStyle = UITextBorderStyleNone;
                ownerHouseNoTextFied.keyboardType = UIKeyboardTypeDecimalPad;
                ownerHouseNoTextFied.font = [UIFont systemFontOfSize: contenfot];
                ownerHouseNoTextFied.textColor=[UIColor blackColor];
                ownerHouseNoTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                ownerHouseNoTextFied.tag=11;
                ownerHouseNoTextFied.placeholder = @"请输入门店编号"; //默认显示的字
                ownerHouseNoTextFied.delegate = self;
                  ownerHouseNoTextFied.text=[dic objectForKey:@"ownerHouseNo"];
                [ownerHouseNoTextFied setUserInteractionEnabled:YES];
                ownerHouseNoTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
                [view2 addSubview:ownerHouseNoTextFied];
                ownerHouseNoTextFied.inputAccessoryView = myToolBar;
                
                UILabel* ownerCardNo=[[UILabel alloc]initWithFrame:CGRectMake(20, 150,70,45)];
                ownerCardNo.text=[NSString stringWithFormat:@"%@", @"业主卡号"];
                ownerCardNo.font=[UIFont systemFontOfSize:contenfot];
                ownerCardNo.textColor=[UIColor blackColor];
                [view2 addSubview:ownerCardNo];
                
                ownerCardNoTextFied=[[UITextField alloc]initWithFrame:CGRectMake(openTime.right,  150, ScreenWidth*500/750,  45)];
                ownerCardNoTextFied.borderStyle = UITextBorderStyleNone;
                ownerCardNoTextFied.keyboardType = UIKeyboardTypeDecimalPad;
                ownerCardNoTextFied.font = [UIFont systemFontOfSize: contenfot];
                ownerCardNoTextFied.textColor=[UIColor blackColor];
                ownerCardNoTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                ownerCardNoTextFied.tag=8;
                ownerCardNoTextFied.placeholder = @"请输入业主卡号"; //默认显示的字
                ownerCardNoTextFied.delegate = self;
                ownerCardNoTextFied.text=[dic objectForKey:@"ownerCardNo"];
                [ownerCardNoTextFied setUserInteractionEnabled:YES];
                ownerCardNoTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
                [view2 addSubview:ownerCardNoTextFied];
                
                
                
                
                UILabel *line14 = [[UILabel alloc]initWithFrame:CGRectMake(15,60, ScreenWidth-30, 0.35)];
                line14.backgroundColor = labelColor;
                [view2 addSubview:line14];
                UILabel *line15 = [[UILabel alloc]initWithFrame:CGRectMake(15,105, ScreenWidth-30, 0.35)];
                line15.backgroundColor = labelColor;
                [view2 addSubview:line15];
                UILabel *line151 = [[UILabel alloc]initWithFrame:CGRectMake(15,150, ScreenWidth-30, 0.35)];
                line151.backgroundColor = labelColor;
                [view2 addSubview:line151];
                
                //333333333333
                view3=[[UIView alloc]initWithFrame:CGRectMake(0, view2.bottom+10, ScreenWidth, 600+45)];
                view3.backgroundColor=[UIColor whiteColor];
                [mainScroll addSubview:view3];
                
                UILabel*jingyingrenzhen=[[UILabel alloc]initWithFrame:CGRectMake(15, 21, 2, 17)];
                jingyingrenzhen.backgroundColor=luseColor;
                [view3 addSubview:jingyingrenzhen];
                UILabel*jingyingrenzhen1=[[UILabel alloc]initWithFrame:CGRectMake(jingyingrenzhen.right+5, 0, 70, 60)];
                jingyingrenzhen1.text=@"经营认证";
                [view3 addSubview:jingyingrenzhen1];
                UILabel*jingyingrenzhen2=[[UILabel alloc]initWithFrame:CGRectMake(jingyingrenzhen1.right+5, 0, 250, 60)];
                jingyingrenzhen2.text=@"(认证后同步生产线上门店)";
                jingyingrenzhen2.textColor=luseColor;
                jingyingrenzhen2.font=[UIFont systemFontOfSize:15];
                [view3 addSubview:jingyingrenzhen2];
                
                
                
                
                
                UILabel* bTypeList=[[UILabel alloc]initWithFrame:CGRectMake(20, 60, 70,45)];
                bTypeList.text=[NSString stringWithFormat:@"%@", @"经营类别"];
                bTypeList.font=[UIFont systemFontOfSize:contenfot];
                bTypeList.textColor=[UIColor blackColor];
                [view3 addSubview:bTypeList];
                
                bTypeListTextField=[[UITextField alloc]initWithFrame:CGRectMake(companyName.right,60, ScreenWidth*500/750,  45)];
                bTypeListTextField.borderStyle = UITextBorderStyleNone;
                bTypeListTextField.font = [UIFont systemFontOfSize: contenfot];
                bTypeListTextField.textColor=luseColor;
                bTypeListTextField.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                bTypeListTextField.tag=9;
                bTypeListTextField.placeholder = @"请选择经验类别"; //默认显示的字
                bTypeListTextField.delegate = self;
//              bTypeListTextField.text=
                [bTypeListTextField setUserInteractionEnabled:NO];
                bTypeListTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
                [view3 addSubview:bTypeListTextField];
                
                
                
                
                
                
                NSString*  string=[[NSString alloc]init];

                
                 NSMutableArray*  bTypeList1=[dic objectForKey:@"bTypeList"];
                for(int i = 0; i < bTypeList1.count; i++){
                    string = [string stringByAppendingString:[NSString stringWithFormat:@"%@  ",  [bTypeList1[i]objectForKey:@"businessType"]]];
                    
                }
                NSLog(@"=========%@",string);
                bTypeListTextField.text=string;

               
                
                
                
                UIButton*jiada=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/2, 60, ScreenWidth/2, 45)];
                [jiada addTarget:self action:@selector(leibie:) forControlEvents:UIControlEventTouchUpInside];
                [view3 addSubview:jiada];
                UIButton*jiada1 = [[UIButton alloc]init];
                jiada1.frame = CGRectMake(ScreenWidth-30,75,8, 13);
                [jiada1 setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
                [jiada1 addTarget:self action:@selector(leibie:) forControlEvents:UIControlEventTouchUpInside];
                [view3 addSubview:jiada1];
                
                
                
                UILabel* bossName=[[UILabel alloc]initWithFrame:CGRectMake(20, 105, 70,45)];
                bossName.text=[NSString stringWithFormat:@"%@", @"店主姓名"];
                bossName.font=[UIFont systemFontOfSize:contenfot];
                bossName.textColor=[UIColor blackColor];
                [view3 addSubview:bossName];
                
                bossNameTextField=[[UITextField alloc]initWithFrame:CGRectMake(companyName.right,105, ScreenWidth*500/750,  45)];
                bossNameTextField.borderStyle = UITextBorderStyleNone;
                bossNameTextField.font = [UIFont systemFontOfSize: contenfot];
                bossNameTextField.textColor=[UIColor blackColor];
                bossNameTextField.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                bossNameTextField.tag=9;
                bossNameTextField.placeholder = @"请输入店主真实姓名"; //默认显示的字
                bossNameTextField.delegate = self;
                bossNameTextField.text=[dic objectForKey:@"bossName"];
                [bossNameTextField setUserInteractionEnabled:YES];
                bossNameTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
                [view3 addSubview:bossNameTextField];
                
                
                
                UILabel* bossIdCardNo=[[UILabel alloc]initWithFrame:CGRectMake(20, 150,70,45)];
                bossIdCardNo.text=[NSString stringWithFormat:@"%@", @"身份证号"];
                bossIdCardNo.font=[UIFont systemFontOfSize:contenfot];
                bossIdCardNo.textColor=[UIColor blackColor];
                [view3 addSubview:bossIdCardNo];
                
                bossIdCardNoTextFied=[[UITextField alloc]initWithFrame:CGRectMake(openTime.right,  150, ScreenWidth*500/750,  45)];
                bossIdCardNoTextFied.borderStyle = UITextBorderStyleNone;
                bossIdCardNoTextFied.font = [UIFont systemFontOfSize: contenfot];
                bossIdCardNoTextFied.textColor=[UIColor blackColor];
                bossIdCardNoTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                bossIdCardNoTextFied.tag=10;
                bossIdCardNoTextFied.placeholder = @"请输入法人身份证"; //默认显示的字
                bossIdCardNoTextFied.delegate = self;
                bossIdCardNoTextFied.text=[dic objectForKey:@"bossIdCardNo"];
                [bossIdCardNoTextFied setUserInteractionEnabled:YES];
                bossIdCardNoTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
                [view3 addSubview:bossIdCardNoTextFied];
                
                
                UILabel *line16 = [[UILabel alloc]initWithFrame:CGRectMake(15,60, ScreenWidth-30, 0.35)];
                line16.backgroundColor = labelColor;
                [view3 addSubview:line16];
                UILabel *line17 = [[UILabel alloc]initWithFrame:CGRectMake(15,105, ScreenWidth-30, 0.35)];
                line17.backgroundColor = labelColor;
                [view3 addSubview:line17];
                UILabel *line18 = [[UILabel alloc]initWithFrame:CGRectMake(15,150, ScreenWidth-30, 0.35)];
                line18.backgroundColor = labelColor;
                [view3 addSubview:line18];
                UILabel *line181 = [[UILabel alloc]initWithFrame:CGRectMake(15,195, ScreenWidth-30, 0.35)];
                line181.backgroundColor = labelColor;
                [view3 addSubview:line181];
                
                
                
                
                UILabel*shangchuanziliao=[[UILabel alloc]initWithFrame:CGRectMake(20, 330/2+45, 200, 60)];
                shangchuanziliao.text=@"上传下列资料即可申请认证";
                shangchuanziliao.font=[UIFont systemFontOfSize:16];
                [view3 addSubview:shangchuanziliao];
                
                UILabel*shangchuanziliao1=[[UILabel alloc]initWithFrame:CGRectMake(shangchuanziliao.right, 330/2+45, 250, 60)];
                shangchuanziliao1.text=@"【申请必读】";
                shangchuanziliao1.textColor=luseColor;
                shangchuanziliao1.font=[UIFont systemFontOfSize:15];
                [view3 addSubview:shangchuanziliao1];
                
                
                farennimage=[[UIButton alloc]initWithFrame:CGRectMake(15, shangchuanziliao1.bottom, ScreenWidth-30, 100)];
//                [farennimage setBackgroundImage:[UIImage imageNamed:@"shangchuangshenfenzheng1"] forState:UIControlStateNormal];
                 [farennimage setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"bossIdCardImgFull"]] placeholderImage:[UIImage imageNamed:@"shangchuangshenfenzheng1"]];
                [view3 addSubview:farennimage];
                
                UITapGestureRecognizer *portraitTap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(editPortrait1)];
                [farennimage addGestureRecognizer:portraitTap1];
                
                
                yingyeimage=[[UIButton alloc]initWithFrame:CGRectMake(15, farennimage.bottom+20, ScreenWidth-30, 100)];
                 [yingyeimage setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"businessLicenseImgFull"]] placeholderImage:[UIImage imageNamed:@"shangchaungyingyezhizhao1"]];
//                [yingyeimage setBackgroundImage:[UIImage imageNamed:@"shangchaungyingyezhizhao1"] forState:UIControlStateNormal];
                [view3 addSubview:yingyeimage];
                
                UITapGestureRecognizer *portraitTap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(editPortrait2)];
                [yingyeimage addGestureRecognizer:portraitTap2];
                
                
                agreementBtn = [[UIButton alloc] initWithFrame:CGRectMake(25, yingyeimage.bottom+20, 16, 16.0)];
                [agreementBtn.layer setCornerRadius:1.0]; //设置矩圆角半径
                [agreementBtn.layer setBorderWidth:0.5];   //边框宽度
                CGColorSpaceRef tureBTnSpace3 = CGColorSpaceCreateDeviceRGB();
                CGColorRef tureBTncolorref3 = CGColorCreate(tureBTnSpace3,(CGFloat[]){204/255.0, 204/255.0, 204/255.0, 1.0});
                [agreementBtn.layer setBorderColor:tureBTncolorref3];//边框颜色
                [agreementBtn addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside];
                [view3 addSubview:agreementBtn];
                
                UIButton*jiadaagreementBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, yingyeimage.bottom+10, 40, 40)];
                [jiadaagreementBtn addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside];
                [view3 addSubview:jiadaagreementBtn];
                
                UILabel* Agreedlabel=[[UILabel alloc]initWithFrame:CGRectMake(48,yingyeimage.bottom+20, 35.0f,16)];
                Agreedlabel.text=@"同意";
                [Agreedlabel setTextColor:[UIColor grayColor]];
                Agreedlabel.font = [UIFont systemFontOfSize:16];
                [view3 addSubview:Agreedlabel];
                
                UIButton* agreement = [[UIButton alloc] initWithFrame:CGRectMake(68,yingyeimage.bottom+20, 180, 16)];
                [agreement setTitle:@"《门店认证确认书》" forState:UIControlStateNormal];
                agreement.titleLabel.font = [UIFont systemFontOfSize: 16.0];
                [agreement setTitleColor:luseColor forState:UIControlStateNormal];
                //  [agreement addTarget:self action:@selector(xieyi:) forControlEvents:UIControlEventTouchUpInside];
                [view3 addSubview:agreement];
                
                renzheng = [[UIButton alloc] initWithFrame:CGRectMake(15,agreement.bottom+30, ScreenWidth-30, anniuHeigth)];
                [renzheng setTitle:@"立即认证" forState:UIControlStateNormal];
                [renzheng setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                renzheng.backgroundColor=luseColor;
                [renzheng.layer setCornerRadius:3.0]; //设置矩圆角半径
                [renzheng.layer setBorderWidth:0.3];   //边框宽度
                CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
                CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){23/255.0,148/255.0, 153/255.0, 1.0});
                [renzheng.layer setBorderColor:tureBTncolorref];//边框颜色
                [renzheng addTarget:self action:@selector(renzheng:) forControlEvents:UIControlEventTouchUpInside];
                [view3 addSubview:renzheng];
                
                closeTimeTextFied.inputAccessoryView = myToolBar;
                openTimeTextFied.inputAccessoryView = myToolBar;
                companyNameTextField.inputAccessoryView = myToolBar;
                phoneTextFied.inputAccessoryView = myToolBar;
                AddressTextFied.inputAccessoryView = myToolBar;
                ProvinceNameTextFied.inputAccessoryView = myToolBar;
                ownerCardNoTextFied.inputAccessoryView = myToolBar;
                bossIdCardNoTextFied.inputAccessoryView = myToolBar;
                ownerNameTextField.inputAccessoryView = myToolBar;
                tv.inputAccessoryView = myToolBar;
                bossNameTextField.inputAccessoryView = myToolBar;
                
                
                [mainScroll setContentSize:CGSizeMake(ScreenWidth, view3.bottom)];

                self.companyImg=[dic objectForKey:@"companyImgUrl"];
                self.companyImgWidth=[dic objectForKey:@"companyImgWidth"];
                self.companyImgHeight=[dic objectForKey:@"companyImgHeight"];
                self.bossIdCardImg=[dic objectForKey:@"bossIdCardImg"];
                self.bossIdCardImgWidth=[dic objectForKey:@"bossIdCardImgWidth"];
                self.bossIdCardImgHeight=[dic objectForKey:@"bossIdCardImgHeight"];
                self.businessLicenseImg=[dic objectForKey:@"businessLicenseImg"];
                self.businessLicenseImgWidth=[dic objectForKey:@"businessLicenseImgWidth"];
                self.businessLicenseImgHeight=[dic objectForKey:@"businessLicenseImgHeight"];
                self.logo=[dic objectForKey:@"logoImgUrl"];
                self.logoImgWidth=[dic objectForKey:@"logoImgWidth"];
                self.logoImgHeight=[dic objectForKey:@"logoImgHeight"];
                
                
                
             

                
                
                
            }else{
                
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];

    
    
}
-(void)leibie:(UIButton*)sender{
//    commdity.sat=@"";
    renzhengleibieViewController *detailViewController = [[renzhengleibieViewController alloc] init];
    [self.navigationController pushViewController:detailViewController animated:YES];
}
//认证
-(void)renzheng:(UIButton*)sender{


    if ([ companyNameTextField.text length] < 1)
    {
        [self showAlertMessage:@"请输入门店名称"];
    }
    else
    {
        if ([self.companyImg length] <1)
        {
            [self showAlertMessage:@"请上传门店图片"];
        }
        else{
            if ([phoneTextFied.text length] <1)
        {
            [self showAlertMessage:@"请输入手机号码"];
        }else {
            if ([ProvinceNameTextFied.text length] <1)
            {
                [self showAlertMessage:@"请选择地区"];
            }
            else{
                if ([AddressTextFied.text length]<1)
                {
                    [self showAlertMessage:@"请输入详细地址"];
                }
                else{
                   if ([bossNameTextField.text length] <1)
                    {
                        [self showAlertMessage:@"请输入法人真实姓名"];
                        }else {
                                if ([bossIdCardNoTextFied.text length] <1)
                            {
                                [self showAlertMessage:@"请输入法人身份证"];
                            }
                            else{
                                if ([ownerNameTextField.text length] <1)
                                {
                                    [self showAlertMessage:@"请输入业主真实姓名"];
                                }
                                else{
                                    
                                    if ([ownerCardNoTextFied.text length] <1)
                                    {
                                        [self showAlertMessage:@"请输入业主物业卡号"];
                                    }else {
                                       
                                        
                                        if ([self.bossIdCardImg length] <1)
                                    {
                                        [self showAlertMessage:@"请上传法人身份证"];
                                    }
                                    else{
                                        
                                        
                                        if ([self.businessLicenseImg length] <1)
                                        {
                                            [self showAlertMessage:@"请上传营业执照图片"];
                                        }
                                        else{
                                            if ([str length] <1)
                                            {
                                                [self showAlertMessage:@"请同意豪德汇协议"];
                                            }
                                            else{
            
            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
            NSString* tokenId = [user objectForKey:@"tokenId"];
            NSString* parentId = [user objectForKey:@"groupId"];
            NSMutableDictionary *params = [NSMutableDictionary new];
            
            [params setValue:[NSString stringWithFormat:@"%@",tokenId] forKey:@"tokenId"];
                                            
            [params setValue:[dic objectForKey:@"companyId"] forKey:@"companyId"];
            [params setValue:companyNameTextField.text forKey:@"companyName"];
            [params setValue:ownerHouseNoTextFied.text forKey:@"ownerHouseNo"];
            [params setValue:self.companyImg forKey:@"companyImg"];
            [params setValue:self.companyImgWidth forKey:@"companyImgWidth"];
            [params setValue:self.companyImgHeight forKey:@"companyImgHeight"];
            [params setValue:openTimeTextFied.text forKey:@"openTime"];
            [params setValue:closeTimeTextFied.text forKey:@"closeTime"];
            [params setValue:phoneTextFied.text forKey:@"phone"];
            [params setValue:ownerNameTextField.text forKey:@"ownerName"];
            [params setValue:ownerCardNoTextFied.text forKey:@"ownerCardNo"];
            [params setValue:bossNameTextField.text forKey:@"bossName"];
            [params setValue:bossIdCardNoTextFied.text forKey:@"bossIdCardNo"];
            
            [params setValue:self.bossIdCardImg forKey:@"bossIdCardImg"];
            [params setValue:self.bossIdCardImgWidth forKey:@"bossIdCardImgWidth"];
            [params setValue:self.bossIdCardImgHeight forKey:@"bossIdCardImgHeight"];
            [params setValue:self.businessLicenseImg forKey:@"businessLicenseImg"];
            [params setValue:self.businessLicenseImgWidth forKey:@"businessLicenseImgWidth"];
            [params setValue:self.businessLicenseImgHeight forKey:@"businessLicenseImgHeight"];
            
            [params setValue:self.logo forKey:@"logoImgUrl"];
            [params setValue:self.logoImgWidth forKey:@"logoImgWidth"];
            [params setValue:self.logoImgHeight forKey:@"logoImgHeight"];

                                            
                            
                                            
            [params setValue:self.jzdprovince forKey:@"province"];
            [params setValue:self.jzdcity forKey:@"city"];
            [params setValue:self.jzddistrict forKey:@"region"];
                                            
            [params setValue:parentId forKey:@"groupId"];
            
            [params setValue:AddressTextFied.text  forKey:@"address"];
                                            
            [params setValue:tv.text  forKey:@"details"];
                                            
    NSMutableArray *mDocumentLine=[NSMutableArray array];
                                            
                                            
        for (int i=0; i<selectFeatureCodeArray.count; i++) {
                                                
                NSMutableDictionary *dics = [NSMutableDictionary dictionary];
                NSString *codeStr = [selectFeatureCodeArray objectAtIndex:i];
                [dics setValue:codeStr forKey:@"code"];
                [mDocumentLine addObject:dics];
                                                
                                                
                }
                                            
                    NSLog(@"====%@",mDocumentLine);
    [params setValue:mDocumentLine  forKey:@"bTypeList"];
                                            
                                            
                                            
     
            NSLog(@"33333333====%@",params);
            
          [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
            
            
            [HttpRequest requestData:@"System/SubmitCompanyAuthInfo" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                if (isSuccess) {
                    
                    NSLog(@"33333333====%@",severDataDict.dataDict);
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        [Global hideProgressHUDInternal:self.view];
                        
                      
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        [Global showTextHudSub:requestResultStr view:self.view];
                        
                        [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
                        
                        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
                        [user setObject:[NSString stringWithFormat:@"%@",@"W"] forKey:@"userAudit"];
                        
                        [user synchronize];

            
                    }else{
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        // [Global showTextHud:requestResultStr view:self.view];
                        [Global showTextHudSub:requestResultStr view:self.view];
                    }
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    
                    [Global showTextHudSub:@"连接失败" view:self.view];
                }
                
            }];
            
        }}}}}}
                } }}
        }
        }}

}

- (void)userNumberLimitTextLength:(UITextField*)textField
{
    if ([textField.text length] > 11)
    {
        textField.text = [textField.text substringToIndex:11];
    }
}

-(void)chooseBtn:(id)sender
{
    saveAccount=!saveAccount;
    if (saveAccount) {
        //        [chooseBtn setImage:[UIImage imageNamed:@"_0000_yixuanzhe.png"] forState:UIControlStateNormal];
        agreementBtn. backgroundColor=luseColor;
        
        str=@"ky";
    }
    else
    {
        //        [chooseBtn setImage:[UIImage imageNamed:@"_0001_weigouxuan.png"] forState:UIControlStateNormal];
        agreementBtn. backgroundColor=nil;
         str=@"";
    }
    
}
- (void)dateChanged:(id)sender
{
    
    UIDatePicker* picker = (UIDatePicker*)sender;
    NSDateFormatter* df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"HH:mm"];
    
    
    
    
    if ([openTimeTextFied isFirstResponder])
    {
        openTimeTextFied.text = [NSString stringWithFormat:@"%@", [df stringFromDate:picker.date]];
        
        
        
    }else{
    
    closeTimeTextFied.text = [NSString stringWithFormat:@"%@", [df stringFromDate:picker.date]];
    }

    
}

-(void)textViewDidChange:(UITextView *)textView
{
    //        self.examineText =  textView.text;
    if (textView.text.length == 0) {
        [imagess removeFromSuperview];
        
        imagess=[[UIImageView alloc]initWithFrame:CGRectMake(15, 8, 51/3, 51/3)];
        imagess.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
        [tv addSubview:imagess];
       
        
    }else{
        [imagess removeFromSuperview];
      
    }
}


- (void)textFieldDidBeginEditing:(UITextField *)textField{
    [self cancelLocatePicker];
    if (textField.tag == 6)
    { [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        mainScroll .frame =CGRectMake(0, -150, ScreenWidth, ScreenHeight);
        [UIView commitAnimations];
        
        
    }
    if (textField.tag == 7)
    { [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        mainScroll .frame =CGRectMake(0, -150, ScreenWidth, ScreenHeight);
        [UIView commitAnimations];
        
        
    }

    if (textField.tag == 8)
    { [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        mainScroll .frame =CGRectMake(0, -150, ScreenWidth, ScreenHeight);
        [UIView commitAnimations];
        
        
    }if (textField.tag == 11)
    { [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        mainScroll .frame =CGRectMake(0, -150, ScreenWidth, ScreenHeight);
        [UIView commitAnimations];
        
        
    }

    if (textField.tag == 9)
    { [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        mainScroll .frame =CGRectMake(0, -250, ScreenWidth, ScreenHeight);
        [UIView commitAnimations];
        
        
    }

    if (textField.tag == 10)
    { [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        mainScroll .frame =CGRectMake(0, -250, ScreenWidth, ScreenHeight);
        [UIView commitAnimations];
        
        
    }

    
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    mainScroll .frame =CGRectMake(0, -100, ScreenWidth, ScreenHeight);
    [UIView commitAnimations];
    
    
    
    return self;
}

-(void)OnTapDone{
    
   
    [closeTimeTextFied resignFirstResponder];
    [openTimeTextFied resignFirstResponder];
    [companyNameTextField resignFirstResponder];
    [phoneTextFied resignFirstResponder];
    [AddressTextFied resignFirstResponder];
    [ProvinceNameTextFied resignFirstResponder];
    
    [tv resignFirstResponder];
    [bossNameTextField resignFirstResponder];
    [bossIdCardNoTextFied resignFirstResponder];
    [ownerNameTextField resignFirstResponder];
    [ownerCardNoTextFied resignFirstResponder];
    [ownerHouseNoTextFied  resignFirstResponder];


    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    mainScroll .frame =CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    [UIView commitAnimations];
    [self cancelLocatePicker];
    
   
}

-(void)closeKeyBoad
{
    
     [closeTimeTextFied resignFirstResponder];
     [openTimeTextFied resignFirstResponder];
     [companyNameTextField resignFirstResponder];
     [phoneTextFied resignFirstResponder];
     [AddressTextFied resignFirstResponder];
     [ProvinceNameTextFied resignFirstResponder];
    
     [tv resignFirstResponder];
     [bossNameTextField resignFirstResponder];
     [bossIdCardNoTextFied resignFirstResponder];
     [ownerNameTextField resignFirstResponder];
     [ownerCardNoTextFied resignFirstResponder];
[ownerHouseNoTextFied  resignFirstResponder];
    
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    mainScroll .frame =CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    [UIView commitAnimations];
    [self cancelLocatePicker];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark portraitImageView getter




- (void)editPortrait {
     self.sat=nil;
    self.sat=@"companyImg";
        
    UIActionSheet *choiceSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                             delegate:self
                                                    cancelButtonTitle:@"取消"
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:@"拍照", @"从相册中选取", nil];
    [choiceSheet showInView:self.view];
}



- (void)editPortrait1 {
       self.sat=nil;
    self .sat=@"bossIdCardImg";
    
    UIActionSheet *choiceSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                             delegate:self
                                                    cancelButtonTitle:@"取消"
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:@"拍照", @"从相册中选取", nil];
    [choiceSheet showInView:self.view];
}

- (void)editPortrait2 {
    self.sat=nil;
    self .sat=@"businessLicenseImg";
        
    UIActionSheet *choiceSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                             delegate:self
                                                    cancelButtonTitle:@"取消"
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:@"拍照", @"从相册中选取", nil];
    [choiceSheet showInView:self.view];
}

- (void)editPortraitlogo {
    self.sat=nil;
    self.sat=@"logo";
    
    UIActionSheet *choiceSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                             delegate:self
                                                    cancelButtonTitle:@"取消"
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:@"拍照", @"从相册中选取", nil];
    [choiceSheet showInView:self.view];
}




#pragma mark VPImageCropperDelegate


#pragma mark UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        [self showCamera];
    }
    
    if (buttonIndex == 1) {
        [self openPhotoAlbum];
    }
}



- (void)showCamera
{
    UIImagePickerController *controller = [[UIImagePickerController alloc] init];
    controller.delegate = self;
    controller.sourceType = UIImagePickerControllerSourceTypeCamera;
    
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        if (self.popover.isPopoverVisible) {
            [self.popover dismissPopoverAnimated:NO];
        }
        
        self.popover = [[UIPopoverController alloc] initWithContentViewController:controller];
        
    } else {
        [self presentViewController:controller animated:YES completion:NULL];
    }
}

- (void)openPhotoAlbum
{
    UIImagePickerController *controller = [[UIImagePickerController alloc] init];
    controller.delegate = self;
    controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        if (self.popover.isPopoverVisible) {
            [self.popover dismissPopoverAnimated:NO];
        }
        
        self.popover = [[UIPopoverController alloc] initWithContentViewController:controller];
        
    } else {
        [self presentViewController:controller animated:YES completion:NULL];
    }
}



- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    image1 = info[UIImagePickerControllerOriginalImage];
    //    [mendianimage setBackgroundImage:image1 forState:UIControlStateNormal];
    
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        if (self.popover.isPopoverVisible) {
            [self.popover dismissPopoverAnimated:NO];
        }
        
        [self openEditor];
    } else {
        [picker dismissViewControllerAnimated:YES completion:^{
            [self openEditor];
        }];
    }
}



- (void)openEditor
{
    PECropViewController *controller = [[PECropViewController alloc] init];
    controller.delegate = self;
    controller.image = image1;
    
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
    
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
    }
    
    [self presentViewController:navigationController animated:YES completion:NULL];
}




- (void)cropViewController:(PECropViewController *)controller didFinishCroppingImage:(UIImage *)croppedImage
{
    [controller dismissViewControllerAnimated:YES completion:NULL];
    if ([self.sat isEqualToString:@"companyImg"]) {
        [mendianimage setImage:croppedImage forState:UIControlStateNormal];
        [mendianimage setContentMode:UIViewContentModeScaleToFill];
    }
    if ([self.sat isEqualToString:@"bossIdCardImg"]) {
        [farennimage setImage:croppedImage forState:UIControlStateNormal];
        [farennimage setContentMode:UIViewContentModeScaleToFill];
    }
    if ([self.sat isEqualToString:@"businessLicenseImg"]) {
        [yingyeimage setImage:croppedImage forState:UIControlStateNormal];
        [yingyeimage setContentMode:UIViewContentModeScaleToFill];
    }
    if ([self.sat isEqualToString:@"logo"]) {
        [imageView setImage:croppedImage forState:UIControlStateNormal];
        [imageView setContentMode:UIViewContentModeScaleToFill];
    }

    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:20 view:self.view];
   
       UIImage *portraitImg = [[UIImage alloc]init];
    portraitImg = [self imageByScalingToMaxSize:croppedImage];
    
    
    UpYun *uy = [[UpYun alloc] init];
    uy.successBlocker = ^(id data)
    {
        [Global hideProgressHUDInternal:self.view];
        
        if ([self.sat isEqualToString:@"companyImg"]) {
            self.companyImg=[data objectForKey:@"url"];
            self.companyImgHeight=[NSString stringWithFormat:@"%@",[data objectForKey:@"image-height"]];
            self.companyImgWidth=[NSString stringWithFormat:@"%@",[data objectForKey:@"image-width"]];
        }
        if ([self.sat isEqualToString:@"bossIdCardImg"]) {
            self.bossIdCardImg=[data objectForKey:@"url"];
            self.bossIdCardImgHeight=[NSString stringWithFormat:@"%@",[data objectForKey:@"image-height"]];
            self.bossIdCardImgWidth=[NSString stringWithFormat:@"%@",[data objectForKey:@"image-width"]];
            
        }
        if ([self.sat isEqualToString:@"businessLicenseImg"]) {
            self.businessLicenseImg=[data objectForKey:@"url"];
            self.businessLicenseImgHeight=[NSString stringWithFormat:@"%@",[data objectForKey:@"image-height"]];
            self.businessLicenseImgWidth=[NSString stringWithFormat:@"%@",[data objectForKey:@"image-width"]];
            
        }
        if ([self.sat isEqualToString:@"logo"]) {
            self.logo=[data objectForKey:@"url"];
            
            self.logoImgHeight=[NSString stringWithFormat:@"%@",[data objectForKey:@"image-height"]];
            self.logoImgWidth=[NSString stringWithFormat:@"%@",[data objectForKey:@"image-width"]];
            
            
        }
        
        
    };
    uy.failBlocker = ^(NSError * error)
    {
        [Global hideProgressHUDInternal:self.view];
        
        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"上传失败" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alert show];
        NSLog(@"%@",error);
    };
    uy.progressBlocker = ^(CGFloat percent, long long requestDidSendBytes)
    {
        
    };
    
    
    [uy uploadFile:portraitImg saveKey:[self getSaveKey]];

    
    
}

- (void)cropViewControllerDidCancel:(PECropViewController *)controller
{
    [controller dismissViewControllerAnimated:YES completion:NULL];
    
    
    
    
    
}





















//#pragma mark VPImageCropperDelegate
//- (void)imageCropper:(VPImageCropperViewController *)cropperViewController didFinished:(UIImage *)editedImage {
//    
//    if ([self.sat isEqualToString:@"companyImg"]) {
//        [mendianimage setImage:editedImage forState:UIControlStateNormal];
//        [mendianimage setContentMode:UIViewContentModeScaleToFill];
//    }
//    if ([self.sat isEqualToString:@"bossIdCardImg"]) {
//        [farennimage setImage:editedImage forState:UIControlStateNormal];
//        [farennimage setContentMode:UIViewContentModeScaleToFill];
//    }
//    if ([self.sat isEqualToString:@"businessLicenseImg"]) {
//        [yingyeimage setImage:editedImage forState:UIControlStateNormal];
//        [yingyeimage setContentMode:UIViewContentModeScaleToFill];
//    }
//    if ([self.sat isEqualToString:@"logo"]) {
//        [imageView setImage:editedImage forState:UIControlStateNormal];
//        [imageView setContentMode:UIViewContentModeScaleToFill];
//    }
//    
//    
//    
//  
//    [cropperViewController dismissViewControllerAnimated:YES completion:^{
//        // TO DO
//    }];
//}
//
//- (void)imageCropperDidCancel:(VPImageCropperViewController *)cropperViewController {
//    [cropperViewController dismissViewControllerAnimated:YES completion:^{
//    }];
//}

//#pragma mark UIActionSheetDelegate
//- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
//    if (buttonIndex == 0) {
//        // 拍照
//        if ([self isCameraAvailable] && [self doesCameraSupportTakingPhotos]) {
//            UIImagePickerController *controller = [[UIImagePickerController alloc] init];
//            controller.sourceType = UIImagePickerControllerSourceTypeCamera;
//            controller.cameraDevice = UIImagePickerControllerCameraDeviceRear;
//            NSMutableArray *mediaTypes = [[NSMutableArray alloc] init];
//            [mediaTypes addObject:(__bridge NSString *)kUTTypeImage];
//            controller.mediaTypes = mediaTypes;
//            controller.delegate = self;
//            [self presentViewController:controller
//                               animated:YES
//                             completion:^(void){
//                                 NSLog(@"Picker View Controller is presented");
//                             }];
//        }
//        
//    } else if (buttonIndex == 1) {
//        // 从相册中选取
//        if ([self isPhotoLibraryAvailable]) {
//            UIImagePickerController *controller = [[UIImagePickerController alloc] init];
//            controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//            NSMutableArray *mediaTypes = [[NSMutableArray alloc] init];
//            [mediaTypes addObject:(__bridge NSString *)kUTTypeImage];
//            controller.mediaTypes = mediaTypes;
//            controller.delegate = self;
//            [self presentViewController:controller
//                               animated:YES
//                             completion:^(void){
//                                 NSLog(@"Picker View Controller is presented");
//                             }];
//        }
//    }
//}

//#pragma mark - UIImagePickerControllerDelegate
//- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
//    [picker dismissViewControllerAnimated:YES completion:^() {
//        UIImage *portraitImg = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
//        portraitImg = [self imageByScalingToMaxSize:portraitImg];
//    
//        VPImageCropperViewController *imgEditorVC = [[VPImageCropperViewController alloc] initWithImage:portraitImg cropFrame:CGRectMake(0, 100.0f, ScreenWidth, ScreenWidth) limitScaleRatio:3];
//        
//        NSLog(@"%@",portraitImg);
//        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:20 view:self.view];
//        
//        self.sendImage = [info objectForKey:UIImagePickerControllerOriginalImage];
//        
//        
//        imgEditorVC.delegate = self;
//        [self presentViewController:imgEditorVC animated:YES completion:^{
//            
//        }];
//    }];
//}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [picker dismissViewControllerAnimated:YES completion:^(){
    }];
}

#pragma mark - UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    
}

#pragma mark camera utility
- (BOOL) isCameraAvailable{
    return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
}

- (BOOL) isRearCameraAvailable{
    return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];
}

- (BOOL) isFrontCameraAvailable {
    return nil;
}

- (BOOL) doesCameraSupportTakingPhotos {
    return [self cameraSupportsMedia:(__bridge NSString *)kUTTypeImage sourceType:UIImagePickerControllerSourceTypeCamera];
}

- (BOOL) isPhotoLibraryAvailable{
    return [UIImagePickerController isSourceTypeAvailable:
            UIImagePickerControllerSourceTypePhotoLibrary];
}
- (BOOL) canUserPickVideosFromPhotoLibrary{
    return [self
            cameraSupportsMedia:(__bridge NSString *)kUTTypeMovie sourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
- (BOOL) canUserPickPhotosFromPhotoLibrary{
    return [self
            cameraSupportsMedia:(__bridge NSString *)kUTTypeImage sourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}

- (BOOL) cameraSupportsMedia:(NSString *)paramMediaType sourceType:(UIImagePickerControllerSourceType)paramSourceType{
    __block BOOL result = NO;
    if ([paramMediaType length] == 0) {
        return NO;
    }
    NSArray *availableMediaTypes = [UIImagePickerController availableMediaTypesForSourceType:paramSourceType];
    [availableMediaTypes enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) {
        NSString *mediaType = (NSString *)obj;
        if ([mediaType isEqualToString:paramMediaType]){
            result = YES;
            *stop= YES;
        }
    }];
    return result;
}
#define ORIGINAL_MAX_WIDTH 420.0f
#pragma mark image scale utility
- (UIImage *)imageByScalingToMaxSize:(UIImage *)sourceImage {
    if (sourceImage.size.width < ORIGINAL_MAX_WIDTH) return sourceImage;
    CGFloat btWidth = 0.0f;
    CGFloat btHeight = 0.0f;
    if (sourceImage.size.width > sourceImage.size.height) {
        btHeight = ORIGINAL_MAX_WIDTH;
        btWidth = sourceImage.size.width * (ORIGINAL_MAX_WIDTH / sourceImage.size.height);
    } else {
        btWidth = ORIGINAL_MAX_WIDTH;
        btHeight = sourceImage.size.height * (ORIGINAL_MAX_WIDTH / sourceImage.size.width);
    }
    CGSize targetSize = CGSizeMake(btWidth, btHeight);
    return [self imageByScalingAndCroppingForSourceImage:sourceImage targetSize:targetSize];
}

- (UIImage *)imageByScalingAndCroppingForSourceImage:(UIImage *)sourceImage targetSize:(CGSize)targetSize {
    UIImage *newImage = nil;
    CGSize imageSize = sourceImage.size;
    CGFloat width = imageSize.width;
    CGFloat height = imageSize.height;
    CGFloat targetWidth = targetSize.width;
    CGFloat targetHeight = targetSize.height;
    CGFloat scaleFactor = 0.0;
    CGFloat scaledWidth = targetWidth;
    CGFloat scaledHeight = targetHeight;
    CGPoint thumbnailPoint = CGPointMake(0.0,0.0);
    if (CGSizeEqualToSize(imageSize, targetSize) == NO)
    {
        CGFloat widthFactor = targetWidth / width;
        CGFloat heightFactor = targetHeight / height;
        
        if (widthFactor > heightFactor)
            scaleFactor = widthFactor; // scale to fit height
        else
            scaleFactor = heightFactor; // scale to fit width
        scaledWidth  = width * scaleFactor;
        scaledHeight = height * scaleFactor;
        
        // center the image
        if (widthFactor > heightFactor)
        {
            thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
        }
        else
            if (widthFactor < heightFactor)
            {
                thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
            }
    }
    UIGraphicsBeginImageContext(targetSize); // this will crop
    CGRect thumbnailRect = CGRectZero;
    thumbnailRect.origin = thumbnailPoint;
    thumbnailRect.size.width  = scaledWidth;
    thumbnailRect.size.height = scaledHeight;
    
    [sourceImage drawInRect:thumbnailRect];
    
    newImage = UIGraphicsGetImageFromCurrentImageContext();
    if(newImage == nil) NSLog(@"could not scale image");
    
    //pop the context to get back to the default
    UIGraphicsEndImageContext();
    return newImage;
}


-(NSString * )getSaveKey {
    /**
     *	@brief	方式1 由开发者生成saveKey
     */
    NSDate *d = [NSDate date];
    return [NSString stringWithFormat:@"/%d/%d/%.0f.png",[self getYear:d],[self getMonth:d],[[NSDate date] timeIntervalSince1970]];
    
    /**
     *	@brief	方式2 由服务器生成saveKey
     */
    //    return [NSString stringWithFormat:@"/{year}/{mon}/{filename}{.suffix}"];
    
    /**
     *	@brief	更多方式 参阅 http://wiki.upyun.com/index.php?title=Policy_%E5%86%85%E5%AE%B9%E8%AF%A6%E8%A7%A3
     */
    
}

- (int)getYear:(NSDate *) date{
    NSDateFormatter *formatter =[[NSDateFormatter alloc] init];
    [formatter setTimeStyle:NSDateFormatterMediumStyle];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSInteger unitFlags = NSYearCalendarUnit;
    NSDateComponents *comps = [calendar components:unitFlags fromDate:date];
    int year=[comps year];
    return year;
}

- (int)getMonth:(NSDate *) date{
    NSDateFormatter *formatter =[[NSDateFormatter alloc] init];
    [formatter setTimeStyle:NSDateFormatterMediumStyle];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSInteger unitFlags = NSMonthCalendarUnit;
    NSDateComponents *comps = [calendar components:unitFlags fromDate:date];
    int month = [comps month];
    return month;
}
-(UIImage *)imageCompress:(UIImage *)image11
{
    UIImage *comImage=image11;
    NSData * sendImageData = UIImageJPEGRepresentation(comImage, 1.0);
    NSUInteger sizeOrigin = [sendImageData length];
    NSUInteger sizeOriginKB = sizeOrigin / 1024;
    
    if (sizeOriginKB >400) {
        float a = 800.0000;
        float b = (float)sizeOriginKB;
        float q = sqrtf(a / b);
        
        CGSize sizeImage = [comImage size];
        CGFloat widthSmall = sizeImage.width * q;
        CGFloat heighSmall = sizeImage.height * q;
        CGSize sizeImageSmall = CGSizeMake(widthSmall, heighSmall);
        
        UIGraphicsBeginImageContext(sizeImageSmall);
        CGRect smallImageRect = CGRectMake(0, 0, sizeImageSmall.width, sizeImageSmall.height);
        [image drawInRect:smallImageRect];
        UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        
        NSData *dataImage = UIImageJPEGRepresentation(smallImage, 1.0);
        sendImageData = dataImage;
        NSLog(@"11111111%f",sizeImageSmall.width);
        NSLog(@"11111111%f",sizeImageSmall.height);
        comImage= smallImage;
        // [_imageview1.image retain];
    }
    return comImage;
}

- (void)showAlertWait
                {
                    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
                    [alt show];
                    
                    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
                    
                }
                
                - (void)showAlertMessage:(NSString *)msg
                {
                    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
                    [alt show];
                    
                    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
                }
                - (void)hideAlert
                {
                    if (alt != nil)
                    {
                        [alt dismissWithClickedButtonIndex:0 animated:YES];
                        alt = nil;
                    }
                }
                

@end
